USE [data]
GO

/****** Object:  UserDefinedFunction [monica].[fn_data_seg_login_tablet]    Script Date: 02/29/2012 15:23:50 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[monica].[fn_data_seg_login_tablet]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [monica].[fn_data_seg_login_tablet]
GO

USE [data]
GO

/****** Object:  UserDefinedFunction [monica].[fn_data_seg_login_tablet]    Script Date: 02/29/2012 15:23:50 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [monica].[sp_data_seg_login_tablet]
	@user varchar(50),
	@clave varchar(50),
	@valido int OUTPUT
AS
	declare 
		@multi          char(1),   
        @estado         char(1),  
        @usr_clave      varchar(10),   
        @user_logon     varchar(10),  
		@encripta       char(1),  
		@Ref   varchar(10)  
	set @multi=''
	select  @multi		= user_mult_log,   
        @estado			= user_status,  
        @usr_clave		= user_clave,  
		@encripta		= encripta_clave  
	from  tb_data_seg_def_user  
	where  user_id = @user
	if @multi = ''
		set @valido = -10;  -- Usuario no existe
	else if @estado <> 'A'
		set @valido = -14;  -- Usuario Inactivo
	else
	begin
		if @encripta = 'S'
			select @clave =  (select monica.fn_data_seg_crypt('C',@clave))
		if @usr_clave <> @clave
			set @valido = -12;  -- Clave Incorrecta
		else
			set @valido = 1 ;  --Clave Correcta
	end
